<?php
namespace Home\Controller;
use Think\Controller;
class QuestionController extends Controller {
    // public function gamelist(){
    //     $games=M('games');#调用表
    //     $this->gamelist=$games->select();##调动成员方法
    //     dump($this->gamelist);
    //     $this->display();
    // }
    public function questionlist(){
		$questionmodel=M('question');
		$question=$questionmodel->order('question_id desc')->select();
		/*dump($goods);*/

		$this->question=$question;
		$this->display();
	}
  public function questiondetail($question_id){
        // $data["id"]=I('get.id');
        // $this->list=M("question")->where($data)->find();
        // $this->display();
        $question = M('question');
        $res = $question->where("question_id = $question_id")->find($data);
        $this->list=$res;
        $this->display();
    
        // $questionmodel=M('question');
        //  $res=$questionModel->where("question_id=$question_id")->find();
      
        // /*dump($goods);*/
        // $this->question=$question;
        // $this->display();
    }
    public function delete($question_id){
   /*dump($_GET);
   echo $id;//如果只写上面这3行，注释部分，会再页面显示要删除的数据 
  */ 
    $questionModel=M('question');
        $res=$questionModel->where("question_id=$question_id")->find();
        $photoPath = realpath("./Public/upload/lessonpic/".$res['lesson_picture']);
        unlink($photoPath);
        //$res=$usersmodel->where("id=$id")->delete();
        if ($questionModel->delete($question_id)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
    }


    public function addquestion(){
        $this->display();

    } 
    Public function doquestion(){
        $data=$_POST;
        $file=$_FILES;
        //dump($file['photo']['size']); 
        //dump($file);      
        $QuestionModel = M('question'); // 实例化User模型
        $QuestionModel->user_name =  I('post.user_name'); // 设置用户的创建时间
        $QuestionModel->question_intro =  I('post.question_intro');
        $QuestionModel->uploaddate =  date("Y-m-d H:i:s"); // 设置用户的创建时间
        $QuestionModel->question_answer = I('post.question_answer');
         //dump($data);
        
      
        
    }

     public function MyUpload(){
                //上传头像
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize  = 3145728 ;// 设置附件上传大小
        //$upload->allowExts  = array('mp4','jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->exts  = array('jpg', 'gif', 'png', 'jpeg');
        $upload->rootPath  =  './';
        $upload->savePath =  'Public/upload/lessonpic/';// 设置附件上传目录

        $upload->autoSub = false;
        $upload->saveName = date("YmdHis").rand(100,999);//定义名字
        // 上传单个文件 
        $info = $upload->upload();                    
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功 获取上传文件信息
                return $info;
            }
    } 

    function editquestion($question_id){
        $question = M('question');
        $res = $question->where("question_id = $question_id")->find($data);
        $this->list=$res;
        $this->display();
    }
    function doUpdate($question_id){
   
        $questionmodel=M('question');
        
        $data['user_name']=I('post.user_name');
        $data['question_intro']=I('post.question_intro');
        $data['question_answer'] = I('post.question_answer');;
        $res=$questionmodel->where("question_id = $question_id")->save($data);
        if (false!==$res){
            $this->success('信息修改成功','questionlist');
        } else{
            $this->error('信息修改失败');
        }
    }




}